package com.niiwoo.civet.trade.dto.newRefund;

import com.niiwoo.civet.base.enums.FeeTypeEnum;
import com.niiwoo.civet.trade.enums.FeeTypeSequenceEnum;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Data
public class RefundFeeDTO implements Comparable<RefundFeeDTO>{
    private Integer period;
    private Date refundDate;
    private Integer feeType;
    private BigDecimal refundingMoney;
    private BigDecimal reducedFee = BigDecimal.ZERO;// 减免利息（提前结清时设置）

    @Override
    public int compareTo(RefundFeeDTO o) {
        if(this.getPeriod() > o.getPeriod()){
            return 1;
        }else if(this.getPeriod().equals(o.getPeriod())){
            int thisSequence = FeeTypeSequenceEnum.enumOf(FeeTypeEnum.enumOf(this.getFeeType())).getSequence();
            int oSequence = FeeTypeSequenceEnum.enumOf(FeeTypeEnum.enumOf(o.getFeeType())).getSequence();
            if(thisSequence > oSequence){
                return 1;
            } else if(thisSequence == oSequence){
                return 0;
            } else{
                return -1;
            }
        }else{
            return -1;
        }
    }

    public static void main(String[] args){
        List<RefundFeeDTO> list = new ArrayList<>();
        RefundFeeDTO r1 = new RefundFeeDTO();
        r1.setPeriod(2);
        RefundFeeDTO r2 = new RefundFeeDTO();
        r2.setPeriod(1);
        list.add(r1);
        list.add(r2);
        Collections.sort(list);
        for (RefundFeeDTO refundFeeDTO : list) {
            System.out.print(refundFeeDTO.getPeriod());
        }
    }
}
